//
//  HJDShareViewController.m
//  常州红房子
//
//  Created by 胡金东 on 16/8/9.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDShareViewController.h"
#import "WXApi.h"
#import "HLActionSheet.h"
static NSString *kLinkURL = @"http://app.wjhfz.com";

static NSString *kLinkTitle = @"专访张小龙：产品之上的世界观";
static NSString *kLinkDescription = @"微信的平台化发展方向是否真的会让这个原本简洁的产品变得臃肿？在国际化发展方向上，微信面临的问题真的是文化差异壁垒吗？腾讯高级副总裁、微信产品负责人张小龙给出了自己的回复。";

@interface HJDShareViewController ()

@end

@implementation HJDShareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"分享";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:19],
       NSForegroundColorAttributeName:[UIColor getColorWithHexNumber:@"848484"]}];

    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(poptoPre) image:@"^" HighImage:nil];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(shareBtnCilck) image:@"矢量智能对象" HighImage:nil];
    
   
    }

-(void)poptoPre
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

-(void)shareBtnCilck
{
    NSArray *titles = @[@"微信",@"朋友圈"];
    NSArray *imageNames = @[@"wechat",@"moments"];
    HLActionSheet *sheet = [[HLActionSheet alloc] initWithTitles:titles iconNames:imageNames];
    [sheet showActionSheetWithClickBlock:^(int btnIndex) {
        if (btnIndex == 0) {
            if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]]) {
                
                SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
                sendReq.bText = NO;//不使用文本信息
                sendReq.scene = 0;
                //创建分享内容对象
                WXMediaMessage *urlMessage = [WXMediaMessage message];
                urlMessage.title = kLinkTitle;//分享标题
                urlMessage.description = kLinkDescription;//分享描述
                [urlMessage setThumbImage:[UIImage imageNamed:@"关于我们"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
                
                //创建多媒体对象
                WXWebpageObject *webObj = [WXWebpageObject object];
                    webObj.webpageUrl = kLinkURL;//分享链接
                
//                webObj.webpageUrl = [NSString stringWithFormat:@"%@?id=%d",Url,self.knowModel.id];
//                NSLog(@"%@",webObj.webpageUrl);
//                NSLog(@"id===%d",self.knowModel.id);
                
                
                //完成发送对象实例
                urlMessage.mediaObject = webObj;
                sendReq.message = urlMessage;
                
                //发送分享信息
                [WXApi sendReq:sendReq];
            }else{
                [MBProgressHUD showError:@"你还没有安装微信,请安装微信"];
            }

        }else if (btnIndex == 1){
            SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
            sendReq.bText = NO;//不使用文本信息
            sendReq.scene = 1;
            //创建分享内容对象
            WXMediaMessage *urlMessage = [WXMediaMessage message];
            urlMessage.title = kLinkTitle;//分享标题
            urlMessage.description = kLinkDescription;//分享描述
            [urlMessage setThumbImage:[UIImage imageNamed:@"testImg"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
            
            //创建多媒体对象
            WXWebpageObject *webObj = [WXWebpageObject object];
                webObj.webpageUrl = kLinkURL;//分享链接
            
//            webObj.webpageUrl = [NSString stringWithFormat:@"%@?id=%d",Url,self.knowModel.id];
//            NSLog(@"%@",webObj.webpageUrl);
//            NSLog(@"id===%d",self.knowModel.id);
            
            
            //完成发送对象实例
            urlMessage.mediaObject = webObj;
            sendReq.message = urlMessage;
            
            //发送分享信息
            [WXApi sendReq:sendReq];

        }else{
             [MBProgressHUD showError:@"你还没有安装微信,请安装微信"];
        }
    } cancelBlock:^{
        NSLog(@"取消");
    }];
}

@end
